package com.zhongwang.mms.module.buy.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.buy.model.ReportPlanModel;
import com.zhongwang.mms.module.buy.service.PlanDelCheckService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 计划删除审核
 *
 * 查看 -> buy:plancheck:view
 * 审核、驳回 -> buy:plancheck:edit
 *
 * @Author: China.sgl
 * @Date: 2020/6/5 8:12
 */
@SuppressWarnings("ALL")
@Slf4j
@Controller
@RequestMapping("/buy/planDelCheck")
public class PlanDelCheckController extends BaseController {

    @Autowired
    private PlanDelCheckService service;

    /**
     * 提报计划删除审核页面
     *
     * @return 路径
     */
    @GetMapping
    @RequiresPermissions({"buy:plancheck:view"})
    public String page(Model model) {
        model.addAttribute("categories", service.findTypes());
        return "buy/planDelCheck/page";
    }

    /**
     * 列表数据
     *
     * @param reportPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"buy:plancheck:view"})
    public JsonResult list(ReportPlanModel reportPlanModel) {
        startPage();
        List<ReportPlanModel> list = service.findReportPlanByQuery(reportPlanModel);
        return jsonResult(list);
    }

    /**
     * 删除提报计划
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/delete")
    @RequiresPermissions({"buy:plancheck:edit"})
    public JsonResult delete(Integer id) {
        return jsonResult(service.deleteById(id));
    }

    /**
     * 批量删除提报计划
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/deleteAll")
    @RequiresPermissions({"buy:plancheck:edit"})
    public JsonResult delete(Integer[] rppIds) {
        return jsonResult(service.deleteInId(rppIds));
    }

    /**
     * 驳回提报计划
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancel")
    @RequiresPermissions({"buy:plancheck:edit"})
    public JsonResult cancel(Integer id) {
        return jsonResult(service.cancelById(id));
    }

    /**
     * 批量驳回提报计划
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancelAll")
    @RequiresPermissions({"buy:plancheck:edit"})
    public JsonResult cancel(Integer[] rppIds) {
        return jsonResult(service.cancelInId(rppIds));
    }

}
